var _n23;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$Ipha_ComponentBasic = require("Ipha_ComponentBasic");
var s = cc__importDefault($1$Ipha_ComponentBasic);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var ccp_menu = cc__decorator.menu;
var def_Ipha_SwayAni = function (t) {
  function _ctor() {
    // 创建实例并设置默认属性
    const instance = null !== t && t.apply(this, arguments) || this;

    // 设置组件名称和相关属性
    instance.comName = "晃动动画";
    instance.m_IsScale = true; // 是否缩放
    instance.m_ScaleScope = 0.1; // 缩放范围
    instance.m_ScaleTime = 0.1; // 缩放时间
    instance.m_SwayScope = 20; // 摇晃范围
    instance.m_SwayOnceTime = 0.05; // 单次摇晃时间
    instance.m_SwayCnt = 2; // 摇晃次数
    instance.m_Delay = 1; // 延迟时间
    instance.m_IsAuto = true; // 自动播放
    instance.m_IsLoop = true; // 是否循环
    instance.m_NodeAngle = 0; // 节点角度
    instance.m_NodeScale = 1; // 节点缩放

    return instance; // 返回实例
  }
  cc__extends(_ctor, t);
  _ctor.prototype.onLoad = function () {
    this.m_NodeAngle = this.node.angle;
    this.m_NodeScale = this.node.scale;
  };
  _ctor.prototype.start = function () {
    if (this.m_IsAuto) {
      this.playAni();
    }
  };
  _ctor.prototype.playAni = function () {
    var ani = this.getTweenAni();
    if (this.m_IsLoop) {
      ani = ani.repeatForever()
    }
    ani.start();
  };
  _ctor.prototype.stopAni = function () {
    cc.Tween.stopAllByTarget(this.node);
    this.node.scale = this.m_NodeScale;
    this.node.angle = this.m_NodeAngle;
  };
  _ctor.prototype.getTweenAni = function () {
    const tween = cc.tween(this.node); // 创建 tween 实例
    const initialScale = this.node.scale; // 获取节点的初始缩放值

    // 如果启用缩放，则添加缩放动画
    if (this.m_IsScale) {
      tween.to(this.m_ScaleTime, {
        scale: initialScale + this.m_ScaleScope
      });
    }

    // 添加摇晃动画
    tween.by(this.m_SwayOnceTime, {
      angle: this.m_SwayScope
    }).by(this.m_SwayOnceTime, {
      angle: -2 * this.m_SwayScope
    });

    // 循环添加摇晃动画
    for (let i = 0; i < this.m_SwayCnt - 1; i++) {
      tween.by(this.m_SwayOnceTime, {
        angle: 2 * this.m_SwayScope
      }).by(this.m_SwayOnceTime, {
        angle: -2 * this.m_SwayScope
      });
    }

    // 最后向节点角度的回归动画
    tween.to(this.m_SwayOnceTime / 2, {
      angle: this.m_NodeAngle
    });

    // 如果启用缩放，则添加最终缩放动画
    if (this.m_IsScale) {
      tween.to(this.m_ScaleTime, {
        scale: this.m_NodeScale
      });
    }

    // 返回动画并设置延迟
    return tween.delay(this.m_Delay).union();
  };
  cc__decorate([ccp_property({
    displayName: "会缩放"
  })], _ctor.prototype, "m_IsScale", undefined);
  cc__decorate([ccp_property({
    displayName: "缩放幅度",
    visible() {
      return this.m_IsScale;
    }
  })], _ctor.prototype, "m_ScaleScope", undefined);
  cc__decorate([ccp_property({
    displayName: "缩放用时",
    visible() {
      return this.m_IsScale;
    }
  })], _ctor.prototype, "m_ScaleTime", undefined);
  cc__decorate([ccp_property({
    displayName: "晃动幅度"
  })], _ctor.prototype, "m_SwayScope", undefined);
  cc__decorate([ccp_property({
    displayName: "单次晃动用时"
  })], _ctor.prototype, "m_SwayOnceTime", undefined);
  cc__decorate([ccp_property({
    displayName: "晃动次数",
    tooltip: "左右一组算一次"
  })], _ctor.prototype, "m_SwayCnt", undefined);
  cc__decorate([ccp_property({
    displayName: "动画重播延迟"
  })], _ctor.prototype, "m_Delay", undefined);
  cc__decorate([ccp_property({
    displayName: "自动播放"
  })], _ctor.prototype, "m_IsAuto", undefined);
  cc__decorate([ccp_property({
    displayName: "循环播放"
  })], _ctor.prototype, "m_IsLoop", undefined);
  return cc__decorate([ccp_ccclass, ccp_menu("ipha组件/简单晃动动画")], _ctor);
}(s.default);
exports.default = def_Ipha_SwayAni;